#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Input;
#endregion

namespace TurbaconPhone
{
    class AboutState : State
    {
        InputState input = new InputState();
        SpriteFont font;
        const int menuEntryPadding = 10;
        Texture2D bg = TurBacon.Content.GetTexture("firebowl_about");
        public AboutState()
        {


        }



        /// <summary>
        /// Controls whether the animation is updated when calling <see cref="Update"/>.
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// Allows the screen to create the hit bounds for a particular menu entry.
        /// </summary>
        protected virtual Rectangle GetMenuEntryHitBounds(MenuEntry entry)
        {
            // the hit bounds are the entire width of the screen, and the height of the entry
            // with some additional padding above and below.
            return new Rectangle(
                0,
                (int)entry.Position.Y - menuEntryPadding,
                TurBacon.Game.GraphicsDevice.Viewport.Width,
                entry.GetHeight() + (menuEntryPadding * 2));
        }

        /// <summary>
        /// Gets the index of the player who is currently controlling this screen,
        /// or null if it is accepting input from any player. This is used to lock
        /// the game to a specific player profile. The main menu responds to input
        /// from any connected gamepad, but whichever player makes a selection from
        /// this menu is given control over all subsequent screens, so other gamepads
        /// are inactive until the controlling player returns to the main menu.
        /// </summary>
        public PlayerIndex? ControllingPlayer
        {
            get { return controllingPlayer; }
            internal set { controllingPlayer = value; }
        }

        PlayerIndex? controllingPlayer;



        /// <summary>
        /// Handler for when the user has cancelled the menu.
        /// </summary>
        protected virtual void OnCancel(PlayerIndex playerIndex)
        {

        }
        /// <summary>
        /// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
        /// </summary>
        protected void OnCancel(object sender, PlayerIndexEventArgs e)
        {
            OnCancel(e.PlayerIndex);
        }
        
        InputState inputState = new InputState();
        public override void EnterState()
        {
            EnabledGestures = GestureType.Tap | GestureType.FreeDrag;
            base.EnterState();

        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            TurBacon.Batch.Begin();
            TurBacon.Batch.Draw(bg, new Rectangle(0, 0, TurBacon.Game.GraphicsDevice.Viewport.Width, TurBacon.Game.GraphicsDevice.Viewport.Height), Color.White);

            TurBacon.Batch.End();
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);


            TurBacon.Batch.Begin();

            TurBacon.Batch.End();
        }



        public override void HandleInput()
        {
            base.HandleInput();
            HandleInput(inputState);
        }

        public override void HandleTap(GestureSample gesture)
        {
            base.HandleTap(gesture);
            // convert the position to a Point that we can test against a Rectangle
            Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
            TurBacon.StateManager.Pop();
            TurBacon.StateManager.Push(new MenuState());

        }
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public void HandleInput(InputState input)
        {
            // we cancel the current menu screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
                    TurBacon.StateManager.Pop();
                    TurBacon.StateManager.Push(new MenuState());

                }
            }
        }
    }
}
